import java.util.Arrays;

public class Main {
    //将数组中的0元素在不改变非零元素相对位置的情况下放到最右边
    public static  void Alg1(int[] array){
        int dest = -1;
        int cur = 0;
        while (cur < array.length){
            if(array[cur] == 0){
                cur++;
            }else {
                //交换
                int tmp = array[cur];
                array[cur] = array[dest+1];
                array[dest + 1] = tmp;

                dest++;
                cur++;
            }
        }
    }
    public static void main(String[] args) {
       int[] array = new int[]{0,1,0,3,12};
       Alg1(array);
       System.out.println(Arrays.toString(array));
    }
}